#include<iostream>
#include<vector>
#include<string>
#include<queue>
using namespace std;



//多源BFS03:地图中最高的点
class Solution3 {
    int dx[4]={0,0,-1,1};
    int dy[4]={-1,1,0,0};
public:
    vector<vector<int>> highestPeak(vector<vector<int>>& isWater) 
    {
        int m=isWater.size();int n=isWater[0].size();
        //vector<vector<int>> height(m);
        queue<pair<int,int>> q;
        for(int i=0;i<m;i++)
            for(int j=0;j<n;j++)
            {
                if(isWater[i][j]==0)
                    isWater[i][j]=-1;
                else
                {
                    isWater[i][j]=0;
                    q.push({i,j});
                }
            }
        while(!q.empty())
        {
            auto [a,b]=q.front();
            q.pop();
            for(int i=0;i<4;i++)
            {
                int x=a+dx[i];
                int y=b+dy[i];
                if(x>=0&&x<m&&y>=0&&y<n&&isWater[x][y]==-1)
                {
                    //cout<<x<<":"<<y<<" ";
                    q.push({x,y});
                    isWater[x][y]=isWater[a][b]+1;
                }
            }
        }
        return isWater;
    }
};

//多源BFS04:地图中最高的点
class Solution4 {
    int dx[4]={0,0,-1,1};
    int dy[4]={-1,1,0,0};
public:
    int maxDistance(vector<vector<int>>& grid) 
    {
        int m=grid.size();int n=grid[0].size();
        queue<pair<int,int>> q;
        for(int i=0;i<m;i++)
            for(int j=0;j<n;j++)
            {
                if(grid[i][j]==1)
                {
                    //cout<<i<<"0"<<j<<" ";
                    q.push({i,j});
                    grid[i][j]=0;
                }
                else
                {
                    //cout<<i<<"-1"<<j<<" ";
                    grid[i][j]=-1;
                }
                    
            }
        while(!q.empty())
        {
            auto [a,b]=q.front();
            q.pop();
            for(int i=0;i<4;i++)
            {
                int x=a+dx[i];
                int y=b+dy[i];
                if(x>=0&&x<m&&y>=0&&y<n&&grid[x][y]==-1)
                {
                    //cout<<x<<":"<<y<<" ";
                    q.push({x,y});
                    grid[x][y]=grid[a][b]+1;
                }
            }
        }
        int ret=0;
        for(int i=0;i<m;i++)
            for(int j=0;j<n;j++)
            {
                ret=ret>grid[i][j]?ret:grid[i][j];
            }
        if(ret==0)  return -1;
        else    return ret;
    }   
};







int main()
{
    return 0;
}